package com.sfh.cpc.com.ui.look;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.widget.TextView;


import com.sfh.cpc.com.R;

import com.sfh.lib.ui.AbstractLifecycleActivity;


import java.util.ArrayList;


public class LookImageActivity extends FragmentActivity implements
        ViewPager.OnPageChangeListener {


    public static void startContentUI(Activity context, ArrayList<String> image,int position) {

        Intent intent = new Intent(context, LookImageActivity.class);
        intent.putExtra("position",position);
        intent.putStringArrayListExtra("images",image);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.activity_zoom_open, 0);
    }

    TextView tvSize;
    HackyViewPager pager;
    ImageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.look_image_activity);
        this.pager = findViewById(R.id.viewPager);
        this.tvSize = findViewById(R.id.tvSize);

        init();
    }

    private void init() {


       ArrayList<String> images = getIntent().getStringArrayListExtra("images");
        if (images == null || images.isEmpty()) {
            return;
        }

        this.pager.addOnPageChangeListener(this);

        this.adapter = new ImageAdapter(images,new ImageAdapter.OnImaegCallbackItem() {
            @Override
            public void onClick() {
                finish();
            }
        });
        this.pager.setAdapter(adapter);
        int position = getIntent().getIntExtra("position",0);
        this.pager.setCurrentItem(position);

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        this.tvSize.setText((position + 1) + "/" + adapter.getCount());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }



}
